﻿using AnyCAD.Foundation;
using AnyCAD.NX.ViewModel;
using Rapid.Sketch.Plugin.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rapid.Sketch.Plugin.Tag
{
    public class UserTagModel : ElementModel
    {
        public GPnt Position = new GPnt();
        public string Content = "Hello World";
        public UserTagModel()
        {

        }

        public TextSceneNode CreateNode()
        {
            var node = TextSceneNode.Create(Content, ColorTable.Red, 10, true);
            node.SetTransform(Matrix4.makeTranslation(Vector3.From(Position)));
            return node;
        }
    }


    class UserTagSchema : ElementSchema
    {
        public UserTagSchema()
                  : base(nameof(UserTagModel))
        {
            SetIcon("/Rapid.Common.Res;component/Image/SectionBar.png");
        }

        // 创建存储数据的类型
        public override Element OnCreateInstance()
        {
            return new UserElement();
        }

        public override ElementModel CreateModel()
        {
            return new UserTagModel();
        }
    }


    /// <summary>
    /// 系统提供的适配器，用来自定义显示对象的保存
    /// </summary>
    class PointInitializer : IUserElementAdaptor
    {
        public string Name { get => nameof(UserTagModel); }
        public PointInitializer()
        {

        }

        public void Show(UserElement element, Document doc, ViewContext vc)
        {
            var model = new UserTagModel();
            model.Load(element);
            var node = model.CreateNode();
            vc.GetScene().AddNode(node);
            vc.RequestUpdate(EnumUpdateFlags.Scene);
        }
    }
}
